package com.nhim.cms.util;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.nhim.cms.dao.CustomWidgetPropertyValueDAO;
import com.nhim.cms.domain.CustomWidgetPropertyValue;

@Service
public class CustomWidgetPropertyValueManager {
	@Autowired
	private CustomWidgetPropertyValueDAO customWidgetPropertyValueDAO;

	@PostConstruct
	public void init() throws Exception {
	}

	@PreDestroy
	public void destroy() {
	}
	
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public CustomWidgetPropertyValue saveOrUpdate(CustomWidgetPropertyValue entity)
			throws Exception {

		CustomWidgetPropertyValue savePropertyValue = customWidgetPropertyValueDAO.saveOrUpdate(entity);
		return savePropertyValue;

	}
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void delete(CustomWidgetPropertyValue propertyValue)
	{
		customWidgetPropertyValueDAO.delete(propertyValue);
	}
	@Transactional(readOnly = true)
	public  List<CustomWidgetPropertyValue> findByCustomWidgetInstanceId(Integer id)
	{
		return customWidgetPropertyValueDAO.findByCustomWidgetInstanceId(id);
		
	}
	
	public static CustomWidgetPropertyValueManager getFromApplicationContext(
			ApplicationContext ctx) {
		return (CustomWidgetPropertyValueManager) ctx
				.getBean(CustomWidgetPropertyValueManager.class);
	}
}
